<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>京城男人帮---我的购物车</title>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/head.css"/>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/footer.css"/>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/go.css"/>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/index.css"/>
	<style type="text/css" media="screen">
			*{
				margin: 0;
				padding: 0;
			}
			html,body{
				width: 100%;
				height: 100%;
				background-size: 100% 100%;
			}
			table{
				width: 100%;
				border-collapse: collapse;
			}
			table tr th{
				text-align: center;
			}
			table tr th:nth-child(2){
				text-align: left;
			}
			table tr{
				height: 80px;
				border-bottom: 1px solid #d4d4d7;
			}
			table tr td:last-child button{
				width: 50%;
				height: 80%;
				background:#C9302C;
				border-radius: 5px;
				border: 0px;
				color: #fff;
				outline: none;
			}
			table tr td{
				text-align: center;
				color: #151515;
				font-family: "微软雅黑";
				/*border: 1px solid #d4d4d7;*/
				padding-left: 5px;
				font-size: 13px;
				height: 30px;
			}
			table tr td:nth-child(2) img{
				height: 150%;
			}
			table tr td:nth-child(4){
				text-align: left;
			}
			table tr:nth-child(even){
				background: #f4f4f4;
			}
			table tr td:nth-child(6) button{
				width: 25px;
				background: #C9302C;
				border: 1px solid #C9302C;
				color: #fff;
				height: 70%;
			}
			table tr td:nth-child(6) input{
				width: 40px;
				height: 69%;
				border: 1px solid #D4D4D7;
				margin: 0px 5px;
				text-align: center;
			}
			.fcred{
				background: #EBEBE4 !important;
			}
	</style>
</head>
<body>
	<div class="header">
		<!--顶部导航-->
        {include file="public/top_nav"}
        <!--顶部导航end-->
		<!--图片-->
		<div class="full_sc order_bottom">
			<div class="w1200 header_conter ">
				<div class="h_c_logo">
    			    <a href="{:url('home/index/index')}">
    				    <img src="__PUBLIC__/home/image/logo.png"  width="102px" height="98px" />
    			    </a>
    		    </div>
    		    <div class="h_c_right">
    		    	<div class="order_Status"></div>
    		    </div>
			</div>
		</div>
		<!--end-->
	</div>

	<!--tip-->
	<div class="public_b">
		<div class="w1200">
			<?php if (!empty($cartData)){ ?>
				<table>
					<tr>
						<td width="50px"><input type="checkbox" id="checkOne">全选</td>
						<th colspan="3" style="padding-left: 50px" width="300px">商品</th>
						<th width="150px">单价</th>
						<th width="150px">数量</th>
						<th width="150px">小计</th>
						<th width="150px">操作</th>
					</tr>
					<tbody id="tab">
					<?php foreach ($cartData as $key => $value){ ?>
					<tr g_id="<?php echo $value['g_id'] ?>" s_id="<?php echo $value['s_id'] ?>">
						<td>
							<input type="checkbox" name="checkAll" class="checkAll" value="<?php echo $value['s_id'] ?>" g_statc="<?php echo $value['g_statc'] ?>">
						</td>
						<td width="80px"><img src="__PUBLIC__/<?php echo $value['g_img'] ?>"></td>
						<td width="220px" style="text-align:left;padding-right: 10px;font-size:11px;">
							<?php echo $value['g_name']; ?>
						</td>
						<td width="150px" style="padding-left: 10px;color:#A8A8A8;font-size:12px;">
							<?php echo str_replace(";","<br>",$value['gui_name']); ?>
						</td>
						<td>￥ <span class="g_price_dj"><?php echo $value['g_price_dj'] ?></span></td>
						<td class="s_num">
							<button ng-click="jian(item,$index)" class="btn-add">-</button>
							<input value="<?php echo $value['s_num'] ?>" disabled="disabled" id="buy_num" class="text_box" type="text" ng-model="item.math">
							<button ng-click="jia(item)" class="btn-reduce">+</button>
						</td>
						<td class="price_sum">￥ <span class="g_price"><?php echo $value['g_price'] ?></span></td>
						<td><button> 移 除 </button></td>
					</tr>
					<?php } ?>
					</tbody>
					<tr>
						<td><input type="checkbox" id="checkOne1">全选</td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td>总购买数量&nbsp;&nbsp;<font class="sum_num" color="red" size="3px">0</font>&nbsp;件</td>
						<td>总价&nbsp;&nbsp;￥<font class="sum_price" color="red" size="3px">0</font></td>
						<td colspan="2"><button id="close"></a>去结算</button></td>
					</tr>
				</table>
			<?php }else{ ?>
		<div class="w1200">
			<div class="car_no_goods">
				<img src="__PUBLIC__/home/image/car_no_goods.jpg"/>
				<div class="no_goods">
					<p class="no_goods_t">亲，您的购物车空空如也，快去抢购心仪商品吧~
					</p>
					<p><a href="{:url('home/index/index')}" class="no_goods_buy">立即购买</a></p>
				</div>
			</div>
			<?php } ?>
			
			<!--为你推荐-->
			<div class="guesslike_div">
				<div class="remat">
					<div class="d_h2">
						<ul>
                            <li class="on">猜你喜欢</li>
                        </ul>
					</div>
					<div class="detail_l_con4">
						<div class="noguess">
						<ul class="day_goods">
				            <?php if (!empty($goodsDataFx)){ ?>
				            <?php foreach ($goodsDataFx as $key => $value){ ?>
				        		<li>
				        			<a href="{:url('home/shop/iemt')}?c_id=<?php echo $value['c_id'] ?>&g_id=<?php echo $value['g_id'] ?>" class="a_con_list">
				        				<p class="p_img"><img src="__PUBLIC__/<?php echo $value['g_img'] ?>"/></p>
				        			</a>
				        			<p class="p_title">
				        				<!-- <span>【7.5折】</span> -->
				        				<?php echo $value['g_name'] ?>
				        			</p>
				        			<p class="p_p">
				        				<span class="price1">￥<span><?php echo $value['g_price'] ?></span></span>
				        				<!-- <span class="price2"><del>￥398.00</del></span> -->
				        				<!-- <a href="{:url('home/shop/iemt')}" class="gwc"></a> -->
				        			</p>
				        		</li>
				            <?php } ?>
				            <?php }else{ ?>
            					暂无商品向您推荐
            				<?php } ?>
				        </ul>
						</div>
					</div>
				</div>
			</div>
			<!--为你推荐-->
		</div>
	</div>
	<!--tipend-->
	
    <!--底部公用-->
    {include file="public/footer"}
    <!--底部end-->
</body>
</html>
<script type="text/javascript" src="__PUBLIC__/home/js/angular.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/home/js/angular-ui-router.min.js" ></script>
<script>
	$(function(){ 
		// 添加
		$(".btn-reduce").click(function(){
			var t = $(this).parent().find('input[class*=text_box]');
			t.val(parseInt(t.val())+1);

			var num = $(this).parent().find('input[class*=text_box]').val();

			var g_price_dj = parseFloat($(this).parents('tr').find("span[class=g_price_dj]").text());

			sum = num*g_price_dj;
			$(this).parents('tr').find("span[class=g_price]").text(sum);

			var g_price = $(this).parents('tr').find("span[class=g_price]").text();

			var g_id = $(this).parents('tr').attr("g_id");
			var s_id = $(this).parents('tr').attr("s_id");
			getTotal()
			db(num,g_price,g_id,s_id);

		})
	 	// 减少
		$(".btn-add").click(function(){
			var t = $(this).parent().find("input[class*=text_box]");
			t.val(parseInt(t.val())-1);
			if(parseInt(t.val())<1){
				t.val(1);
			}
			var num = $(this).parent().find('input[class*=text_box]').val();

			var g_price_dj = parseFloat($(this).parents('tr').find("span[class=g_price_dj]").text());
			sum = num*g_price_dj;
			$(this).parents('tr').find("span[class=g_price]").text(sum);

			var g_price = $(this).parents('tr').find("span[class=g_price]").text();
			var g_id = $(this).parents('tr').attr("g_id");
			var s_id = $(this).parents('tr').attr("s_id");
			getTotal()
			db(num,g_price,g_id,s_id);
		})
		function db(num,g_price,g_id,s_id){
			$.ajax({
				url:"submitNum",
				type:"post",
				dataType:"json",
				data:{num:num,g_price:g_price,g_id:g_id,s_id:s_id},
				success:function(res){
					if(res==2){
						alert("登录已过期，请重新登录");
						window.location.href = "{:url('home/user/login')}";
					}
				}
			})
		}
		// 全选
		$(document).on("click","#checkOne,#checkOne1",function(){
			if($(this).prop("checked")){
				$("#checkOne").prop("checked",true);
				$("#checkOne1").prop("checked",true);
	           	$(".checkAll").prop("checked",true);
			}else{
				$("#checkOne").prop("checked",false);
				$("#checkOne1").prop("checked",false);
	           	$(".checkAll").prop("checked",false);
			}
			getTotal()
		});
		$(".checkAll").click(function () {
			var len =   $(".checkAll").length;
			var checkedLen  =   $(".checkAll:checked").length;
			if(len  ==  checkedLen){
				$('#checkOne').prop('checked', true);
				$('#checkOne1').prop('checked', true);
			}else{
				$('#checkOne').prop('checked', false);
				$('#checkOne1').prop('checked', false);
			}
			getTotal()
		})
		getTotal();
		function getTotal() {
			var sum_num =  0;
			var sum_price =  0;
			$(".checkAll").each(function () {
				if(this.checked == true){
					var s_num  =  $(this).parent().siblings('.s_num').find('input[class*=text_box]').val();
					var price_sum  =  $(this).parent().siblings('.price_sum').find('span').text();
					sum_num += Number(s_num);
					sum_price += Number(price_sum);
				}
			})
			$(".sum_num").text(sum_num);
			$(".sum_price").text(sum_price);
		}

		$("#close").click(function(event) {
			var checkAll = $('input[class=checkAll]:checked').length;
			if(checkAll>=1){
				var sum_num = $(".sum_num").text();
				var sum_price = $(".sum_price").text();
				if(sum_num!=0 && sum_price!=0){
					var s_id = '';
					var g_statc = '';
					$(".checkAll").each(function () {
						if(this.checked == true){
							s_id += ","+$(this).val();
							g_statc += ","+$(this).attr("g_statc");
						}
					})
					$.ajax({
						url:"submitStatc",
						type:"post",
						dataType:"json",
						data:{s_id:s_id,g_statc:g_statc},
						success:function(res){
							if(res==1){
								window.open("{:url('home/cart/submitpath')}");
							}else{
								alert("登录已过期，请重新登录");
								window.location.href = "{:url('home/user/login')}";
							}
						}
					})
				}else{
					alert("请重新选择");
				}
			}else{
				alert("最少选择一个商品");
			}
		});
	})

</script>
